package com.example.xss.surfaceviewtest.myview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.support.v4.widget.DrawerLayout;
import android.util.AttributeSet;
import android.view.View;

import com.example.xss.surfaceviewtest.R;

/**
 * Created by Administrator on 2018/11/6 0006.
 */

public class MyView extends View {
    private Context context;
    private Paint paint;
    private Bitmap bitmap;

    public MyView(Context context) {
        this(context, null);
    }

    public MyView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setColor(Color.BLUE);
        paint.setTextSize(50f);
        paint.setAntiAlias(true);//开启抗锯齿
        paint.setStyle(Paint.Style.STROKE);//设置画笔空心
        bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (null != bitmap) {
            canvas.drawBitmap(bitmap, getLeft(), getTop(), paint);
            canvas.save();
            canvas.rotate(90f);
            canvas.drawText("12324324",0,0,paint);
            canvas.restore();
        }
    }
}
